package com.bier.fishproject.adapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.bier.fishproject.R;
import com.bier.fishproject.entity.Bill;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class BillListAdapter extends BaseAdapter{
	
	private Context context;
	private List<Bill> list;
	public Bill b;
	public Map<String, String> map=new HashMap<String, String>();
	public BillListAdapter(Context context,List<Bill> list) {
		super();
		this.context = context;
		this.list=list;
	}

	@Override
	public int getCount() {
		return list==null ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHolder holder = null;
		if(view==null){
			holder = new ViewHolder(); 
			view = LayoutInflater.from(context).inflate(R.layout.bill_item, null);
			holder.rel=(RelativeLayout)view.findViewById(R.id.rel_bi);
			holder.tvMonth=(TextView)view.findViewById(R.id.tv_bi_month);
			holder.tvTotal=(TextView)view.findViewById(R.id.tv_bi_total);
			holder.tvSaleno=(TextView)view.findViewById(R.id.tv_bi_saleno);
			holder.tvType=(TextView)view.findViewById(R.id.tv_bi_ptype);
			holder.tvTime=(TextView)view.findViewById(R.id.tv_bi_time);
			holder.tvMoney=(TextView)view.findViewById(R.id.tv_bi_money);
			view.setTag(holder);
		}else{
			holder=(ViewHolder)view.getTag();
		}
		b=list.get(position);
		if(b!=null){
			holder.tvTotal.setVisibility(View.GONE);
			if(map.get(b.getStart_time().substring(5, 7))==null){
				map.put(b.getStart_time().substring(5, 7), b.getStart_time().substring(5, 7));
				holder.rel.setVisibility(View.VISIBLE);
				holder.tvMonth.setText(b.getStart_time().substring(5, 7)+"月");
			}else{
				holder.rel.setVisibility(View.GONE);
			}
			holder.tvSaleno.setText("流水号："+b.getSaleno());
			if(b.getPay_type().equals("0")){
				holder.tvType.setText("计时");
			}else if(b.getPay_type().equals("1")){
				holder.tvType.setText("计量");
			}else if(b.getPay_type().equals("2")){
				holder.tvType.setText("智能");
			}
			if(!b.getStart_time().equals("0")){
				holder.tvTime.setText(b.getStart_time().substring(5, 16));
			}
			holder.tvMoney.setText(b.getMoney()+"元");
		}
		return view;
	}
	
	private class ViewHolder{
		private RelativeLayout rel;
		private TextView tvMonth,tvTotal,tvSaleno,tvType,tvTime,tvMoney;
	 }

}
